package com.yy.dongtai;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * {@code InvocationHandler} is the interface implemented by
 *   the <i>invocation handler</i> of a proxy instance.
 * @param <T> 表示被代理的类的类型
 */
public class StuInvocationHandler <T> implements InvocationHandler {

    //声明被代理的类
    T target;
    public StuInvocationHandler(T target){
        this.target=target;
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //在这里调用被代理对象的方法 利用反射技术
        System.out.println("代理执行"+method.getName()+"   方法");
        //反射
        Object result = method.invoke(target, args);
        return result;
    }
}
